package com.lmk.Test;

import com.lmk.utils.ArrayTools;
import org.junit.jupiter.api.Test;

import java.lang.reflect.Array;
import java.util.Arrays;

/**
 * 测试类
 */

public class CommenTest {

    @Test
    public void testContains(){
        int[] n={2,7,4,3,8,1};
        int m=8;
        boolean has= ArrayTools.contains(n,m);

        System.out.println("包含"+m+":"+has);
    }
   @Test
    public void testSwap(){
        int[] n={2,7,4,3,8,1};
       ArrayTools.swap(n,2,4);
       System.out.println(Arrays.toString(n));
    }
    @Test
    public void testMax(){
        int[] n={2,7,4,3,8,1};
        int max=n[0];
        for (int i = 1; i < n.length; i++) {
            if(n[i]>max){
                max=n[i];

            }

        } System.out.println(max);
    }
    @Test
    public void testAvg(){
        int[] n={2,7,4,3,8,1};
        int sun=0;
        for (int m:n
             ) {
            sun+=m;
        }
      double  avg=sun*1.0/n.length;
        System.out.println(avg);
    }

    @Test
    public void testReverse(){
        int[] a={1,2,3,4,5};
        for (int i = 0; i <a.length/2 ; i++) {
            ArrayTools.swap(a, i,a.length-1-i);

        }
        System.out.println(Arrays.toString(a));

    }

}
